import 'dart:io';

import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';

import 'security_defend_wall_platform_interface.dart';

/// An implementation of [SecurityDefendWallPlatform] that uses method channels.
class MethodChannelSecurityDefendWall extends SecurityDefendWallPlatform {
  /// The method channel used to interact with the native platform.
  @visibleForTesting
  final methodChannel = const MethodChannel('security_defend_wall');

  @override
  Future<String?> getPlatformVersion() async {
    final version = await methodChannel.invokeMethod<String>('getPlatformVersion');
    return version;
  }

  @override
  Future<bool> isTampered(String signature, String iosTeamId) async {
    final isTampered = await methodChannel.invokeMethod<bool>('isTampered',
        Platform.isIOS ? {
            'teamId': iosTeamId,
          }: {
            'signature': signature,
          }
       );
    return isTampered ?? false;
  }

  @override
  Future<bool> isRooted() async {
    final isRooted = await methodChannel.invokeMethod<bool>('isRooted');
    return isRooted ?? false;
  }

  @override
  Future<bool> isEmulator() async {
    final isEmulator = await methodChannel.invokeMethod<bool>('isEmulator');
    return isEmulator ?? true;
  }

  @override
  Future<bool> isDebugged() async {
    final isDebugged = await methodChannel.invokeMethod<bool>('isDebugged');
    return isDebugged ?? false;
  }
}
